package org.erp.procurement.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.procurement.convert.ProductReportConvert;
import org.erp.procurement.entity.ProductReport;
import org.erp.procurement.entity.bo.ProductReportAddBo;
import org.erp.procurement.service.ProductReportService;
import org.springframework.web.bind.annotation.*;

import static org.erp.common.domain.Result.success;

/**
 * 产品质检报告控制层
 *
 * @author libin
 * @version 1.0
 * @description: 产品质检报告控制层
 * @date 2025/11/6 11:37
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/report")
public class ProductReportController {

    private final ProductReportService productReportService;

    private final ProductReportConvert productReportConvert;

    /**
     * 添加产品质检报告信息
     *
     * @param productReportAddBo
     * @return
     */
    @PostMapping("/save")
    public Result<String> reportSave(@RequestBody ProductReportAddBo productReportAddBo) {
        productReportService.reportSave(productReportConvert.boConvert(productReportAddBo));
        return success();
    }

    @GetMapping("/find/{productId}")
    public Result<ProductReport> findByProductId(@PathVariable("productId") Long productId) {
        return Result.success(productReportService.findByProductId(productId));
    }
}
